package com.bishe.serivce.Impl;

import cn.hutool.core.collection.CollUtil;
import com.bishe.dao.ClientinfoDao;
import com.bishe.pojo.Clientinfo;
import com.bishe.pojo.Message;
import com.bishe.serivce.IClientinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 客户接口实现
 * @date 2022/03/02 38:11:51
 */
@Service
public class ClientinfoServiceImpl implements IClientinfoService {
    @Autowired
    private ClientinfoDao clientinfoDao;


    @Override
    public List<Clientinfo> findAll() {
        return clientinfoDao.findAll();
    }

    @Override
    public Clientinfo findById(String id) {
        return clientinfoDao.findById(id);
    }

    @Override
    public void deleteById(String id) {
        clientinfoDao.deleteById(id);

    }

    @Override
    public void updateById(Clientinfo clientinfo) {
        clientinfoDao.updateById(clientinfo);
    }

    @Override
    public void save(Clientinfo clientinfo) {
        clientinfoDao.save(clientinfo);

    }

    @Override
    public List<String> getUserNames() {
        List<Clientinfo> all = clientinfoDao.findAll();
        List<String> names = new ArrayList<>(all.size());
        if (CollUtil.isNotEmpty(all)){
            names = all.stream().map(Clientinfo::getName).collect(Collectors.toList());
        }
        return names;
    }

}